using System;
using System.Collections.Generic;
using System.Text;
using GiftNet.IDAL;
using GiftNet.Model;
using GiftNet.DALFactory;
using System.IO; 

namespace GiftNet.AppBLL
{
    public class OrderStatManager
    {
        public System.Collections.Generic.IList<GiftNet.Model.OrderStatByMonth> GetOrderStatByMonthList(string sqlStr)
        {
            System.Collections.Generic.IList<GiftNet.Model.OrderStatByMonth> ms = new System.Collections.Generic.List<GiftNet.Model.OrderStatByMonth>();
            System.Data.IDataReader reader = GiftNet.AppBLL.AppManager.ExeViewOrSQL(sqlStr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    ms.Add(new OrderStatByMonth(int.Parse(reader["Year"].ToString()),
                        int.Parse(reader["Month"].ToString()),
                        short.Parse(reader["OrderState"].ToString()),
                        double.Parse(reader["MonthAmout"].ToString()),
                        double.Parse(reader["MonthAccount"].ToString()),
                         int.Parse(reader["MonthQuantity"].ToString())
                        ));
                }

                reader.Close();
            }

            return ms;
        }


        public System.Collections.Generic.IList<GiftNet.Model.OrderStatByYear> GetOrderStatByYearList(string sqlStr)
        {
            System.Collections.Generic.IList<GiftNet.Model.OrderStatByYear> ms = new System.Collections.Generic.List<GiftNet.Model.OrderStatByYear>();
            System.Data.IDataReader reader = GiftNet.AppBLL.AppManager.ExeViewOrSQL(sqlStr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    ms.Add(new OrderStatByYear(int.Parse(reader["Year"].ToString()), 
                        short.Parse(reader["OrderState"].ToString()),
                        double.Parse(reader["YearAmout"].ToString()),
                        double.Parse(reader["YearAccount"].ToString()),
                         int.Parse(reader["YearQuantity"].ToString())
                        ));
                }

                reader.Close();
            }

            return ms;
        }


        public System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByDay> GetVwProductSaleByDayList(string sqlStr)
        {
            System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByDay> ms = new System.Collections.Generic.List<GiftNet.Model.VwProductSaleByDay>();
            System.Data.IDataReader reader = GiftNet.AppBLL.AppManager.ExeViewOrSQL(sqlStr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    ms.Add(new VwProductSaleByDay(new Guid(reader["ProID"].ToString()),
                        reader["Name"].ToString(),
                        reader["Logo"].ToString(),
                        reader["Code"].ToString(),
                        double.Parse(reader["Price"].ToString()),
                        double.Parse(reader["MarketPrice"].ToString()),
                        reader["Bill"].ToString(),
                        reader["Introduce"].ToString(),
                        double.Parse(reader["DisCount"].ToString()),
                        long.Parse(reader["SaleAmount"].ToString()),
                        double.Parse(reader["Bulk"].ToString()),
                        double.Parse(reader["Weight"].ToString()),
                        bool.Parse(reader["Individuation"].ToString()),
                        bool.Parse(reader["Pack"].ToString()),
                        bool.Parse(reader["Comment"].ToString()),
                        bool.Parse(reader["Boon"].ToString()),
                        bool.Parse(reader["Publish"].ToString()),
                        bool.Parse(reader["ReCommend"].ToString()),
                        bool.Parse(reader["Zone"].ToString()),
                        bool.Parse(reader["Hot"].ToString()),
                        DateTime.Parse(reader["LastPayment"].ToString()),
                        reader["Note"].ToString(),
                        int.Parse(reader["Mark"].ToString()),
                        short.Parse(reader["State"].ToString()),
                        DateTime.Parse(reader["CreateDate"].ToString()),
                        bool.Parse(reader["Overdue"].ToString()),
                        DateTime.Parse(reader["SaleTime"].ToString()),
                        DateTime.Parse(reader["StopTime"].ToString()),
                        reader["CommendWord"].ToString(),
                        reader["BarCode"].ToString(),
                        reader["Size"].ToString(),
                        reader["Stuff"].ToString(),
                        reader["Place"].ToString(),
                        reader["Level"].ToString(),
                        reader["Color"].ToString(),
                        reader["ProductMode"].ToString(),
                        reader["ProductType"].ToString(),
                        DateTime.Parse(reader["CommendDate"].ToString()),
                        reader["IndexDisplay"].ToString(),
                        reader["LoveFlag"].ToString(),
                        double.Parse(reader["SumMoney"].ToString()),
                        double.Parse(reader["SumIndivPrice"].ToString()),
                        double.Parse(reader["SumIndivPackPrice"].ToString()),
                        double.Parse(reader["SumQuantity"].ToString()),
                        reader["Year"].ToString(),
                        reader["Month"].ToString(),
                        reader["Day"].ToString(),
                        new Guid(reader["StorageId"].ToString()),
                        new Guid(reader["Product"].ToString()),
                         reader["TakeTime"].ToString() 
                        ));
                }

                reader.Close();
            }

            return ms;
        }


        public System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByMonth> GetVwProductSaleByMonthList(string sqlStr)
        {
            System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByMonth> ms = new System.Collections.Generic.List<GiftNet.Model.VwProductSaleByMonth>();
            System.Data.IDataReader reader = GiftNet.AppBLL.AppManager.ExeViewOrSQL(sqlStr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    ms.Add(new VwProductSaleByMonth(reader["TakeTime"].ToString(), new Guid(reader["ProID"].ToString()),
                        reader["Name"].ToString(),
                        reader["Logo"].ToString(),
                        reader["Code"].ToString(),
                        double.Parse(reader["Price"].ToString()),
                        double.Parse(reader["MarketPrice"].ToString()),
                        reader["Bill"].ToString(),
                        reader["Introduce"].ToString(),
                        double.Parse(reader["DisCount"].ToString()),
                        long.Parse(reader["SaleAmount"].ToString()),
                        double.Parse(reader["Bulk"].ToString()),
                        double.Parse(reader["Weight"].ToString()),
                        bool.Parse(reader["Individuation"].ToString()),
                        bool.Parse(reader["Pack"].ToString()),
                        bool.Parse(reader["Comment"].ToString()),
                        bool.Parse(reader["Boon"].ToString()),
                        bool.Parse(reader["Publish"].ToString()),
                        bool.Parse(reader["ReCommend"].ToString()),
                        bool.Parse(reader["Zone"].ToString()),
                        bool.Parse(reader["Hot"].ToString()),
                        DateTime.Parse(reader["LastPayment"].ToString()),
                        reader["Note"].ToString(),
                        int.Parse(reader["Mark"].ToString()),
                        short.Parse(reader["State"].ToString()),
                        DateTime.Parse(reader["CreateDate"].ToString()),
                        bool.Parse(reader["Overdue"].ToString()),
                        DateTime.Parse(reader["SaleTime"].ToString()),
                        DateTime.Parse(reader["StopTime"].ToString()),
                        reader["CommendWord"].ToString(),
                        reader["BarCode"].ToString(),
                        reader["Size"].ToString(),
                        reader["Stuff"].ToString(),
                        reader["Place"].ToString(),
                        reader["Level"].ToString(),
                        reader["Color"].ToString(),
                        reader["ProductMode"].ToString(),
                        reader["ProductType"].ToString(),
                        DateTime.Parse(reader["CommendDate"].ToString()),
                        reader["IndexDisplay"].ToString(),
                        reader["LoveFlag"].ToString(),
                        double.Parse(reader["SumMoney"].ToString()),
                        double.Parse(reader["SumIndivPrice"].ToString()),
                        double.Parse(reader["SumIndivPackPrice"].ToString()),
                        double.Parse(reader["SumQuantity"].ToString()),
                        reader["Year"].ToString(),
                        reader["Month"].ToString(), 
                        new Guid(reader["StorageId"].ToString()),
                        new Guid(reader["Product"].ToString())


                        ));
                }

                reader.Close();
            }

            return ms;
        }

        public System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByYear> GetVwProductSaleByYearList(string sqlStr)
        {
            System.Collections.Generic.IList<GiftNet.Model.VwProductSaleByYear> ms = new System.Collections.Generic.List<GiftNet.Model.VwProductSaleByYear>();
            System.Data.IDataReader reader = GiftNet.AppBLL.AppManager.ExeViewOrSQL(sqlStr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    ms.Add(new VwProductSaleByYear(reader["TakeTime"].ToString(),new Guid(reader["ProID"].ToString()),
                        reader["Name"].ToString(),
                        reader["Logo"].ToString(),
                        reader["Code"].ToString(),
                        double.Parse(reader["Price"].ToString()),
                        double.Parse(reader["MarketPrice"].ToString()),
                        reader["Bill"].ToString(),
                        reader["Introduce"].ToString(),
                        double.Parse(reader["DisCount"].ToString()),
                        long.Parse(reader["SaleAmount"].ToString()),
                        double.Parse(reader["Bulk"].ToString()),
                        double.Parse(reader["Weight"].ToString()),
                        bool.Parse(reader["Individuation"].ToString()),
                        bool.Parse(reader["Pack"].ToString()),
                        bool.Parse(reader["Comment"].ToString()),
                        bool.Parse(reader["Boon"].ToString()),
                        bool.Parse(reader["Publish"].ToString()),
                        bool.Parse(reader["ReCommend"].ToString()),
                        bool.Parse(reader["Zone"].ToString()),
                        bool.Parse(reader["Hot"].ToString()),
                        DateTime.Parse(reader["LastPayment"].ToString()),
                        reader["Note"].ToString(),
                        int.Parse(reader["Mark"].ToString()),
                        short.Parse(reader["State"].ToString()),
                        DateTime.Parse(reader["CreateDate"].ToString()),
                        bool.Parse(reader["Overdue"].ToString()),
                        DateTime.Parse(reader["SaleTime"].ToString()),
                        DateTime.Parse(reader["StopTime"].ToString()),
                        reader["CommendWord"].ToString(),
                        reader["BarCode"].ToString(),
                        reader["Size"].ToString(),
                        reader["Stuff"].ToString(),
                        reader["Place"].ToString(),
                        reader["Level"].ToString(),
                        reader["Color"].ToString(),
                        reader["ProductMode"].ToString(),
                        reader["ProductType"].ToString(),
                        DateTime.Parse(reader["CommendDate"].ToString()),
                        reader["IndexDisplay"].ToString(),
                        reader["LoveFlag"].ToString(),
                        double.Parse(reader["SumMoney"].ToString()),
                        double.Parse(reader["SumIndivPrice"].ToString()),
                        double.Parse(reader["SumIndivPackPrice"].ToString()),
                        double.Parse(reader["SumQuantity"].ToString()),
                        reader["Year"].ToString(), 
                        new Guid(reader["StorageId"].ToString()),
                        new Guid(reader["Product"].ToString())


                        ));
                }

                reader.Close();
            }

            return ms;
        }


        private static readonly IOrderStaByDay OrderStaByDayDAL = DataAccess.CreateIOrderStaByDay();


        public IList<GiftNet.Model.OrderStaByDay> GetOrderStaByDayList(string strWhere)
        {
            return OrderStaByDayDAL.GetModelList(strWhere);
        }
 
        public IList<GiftNet.Model.OrderStaByDay> GetOrderStaByDayList(int PageSize, int PageIndex, out int recordCount, string strWhere)
        {
            return OrderStaByDayDAL.GetModelList(PageSize, PageIndex, out recordCount, strWhere);
        }

    }
}
